﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using InputBoxSample;
using PatentApp.Models;
using PatentApp.Data;

namespace PatentApp
{
    public partial class dlgSearch : Form
    {
        public dlgSearch()
        {
            InitializeComponent();
        }

        private void btnAddCancel_Click(object sender, EventArgs e)
        {
            DialogResult = DialogResult.OK;
        }

        private void btnAddNext_Click(object sender, EventArgs e)
        {
            result = null;
            switch (ddlFindCategory.SelectedIndex)
            {
                case 0:
                    using (var session = NHibernateCfg.OpenSession())
                        result =
                            (from prods in session.QueryOver<Produkt>()
                             where prods.ProduktId == int.Parse(txtFindValue.Text)
                             select prods).SingleOrDefault();
                    break;
                case 1:
                    using (var session = NHibernateCfg.OpenSession())
                        result =
                            (from prods in session.QueryOver<Produkt>()
                             where prods.NrOgolny == int.Parse(txtFindValue.Text)
                             select prods).SingleOrDefault();
                    break;
                case 2:
                    using (var session = NHibernateCfg.OpenSession())
                        result =
                            (from prods in session.QueryOver<Produkt>()
                             where prods.NrRoczny == int.Parse(txtFindValue.Text)
                             select prods).SingleOrDefault();
                    break;
                case 3:
                    using (var session = NHibernateCfg.OpenSession())
                        result =
                            (from prods in session.QueryOver<Produkt>()
                             where prods.NrZgloszenia == txtFindValue.Text
                             select prods).SingleOrDefault();
                    break;
                case 4:
                    using (var session = NHibernateCfg.OpenSession())
                        result =
                            (from prods in session.QueryOver<Produkt>()
                             where prods.NrPatentu == txtFindValue.Text
                             select prods).SingleOrDefault();
                    break;
                default:
                    break;
            }
            if (result == null)
                MessageBox.Show("Nie znalezionego zgłoszenia o podobnym kryterium");
            else
                this.DialogResult = DialogResult.OK;
        }

        public Produkt result {get; set; }

    }
}
